/*
 * @Copyright: 2014~2018 www.yyfax.com Inc. All rights reserved.
 */
package com.linln.core.utils;

import java.io.Closeable;
import java.io.IOException;

import lombok.extern.slf4j.Slf4j;

/**
 * 可关闭的对象
 *
 * @author jiangmy
 * @date 2018年1月15日 下午4:52:54
 * @since 1.0.0
 */
@Slf4j
public class CloseableUtils {

    /**
     * 关闭一个可关闭对象
     *
     * @param closeables 可关闭对象
     * @return 是否成功关闭
     */
    public static boolean safeClose(Closeable... closeables) {
        boolean success = true;
        for (Closeable closeable : closeables) {
            if (null != closeable) {
                try {
                    closeable.close();
                } catch (IOException e) {
                    log.error("close " + closeable + " failed !!!", e);
                    success = false;
                }
            }
        }
        return success;
    }

    private CloseableUtils() {
    }
}
